home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / bed.lua < prev    next >
Text File  |  2004-01-29  |  1KB  |  47 lines

  1. -- bed  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.     
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_sleep", "sleep");
  12.         button.addDescription(ACTIVITY, "sleep");
  13.         -- can always be selected by user
  14.         button.addDescription(ALWAYS_USERSELECTABLE, "true");
  15.         -- button.addIcon("guiIconComfort");
  16.  
  17.     end )
  18.     
  19.     -- lay on bed
  20.     onMsg("sleep", function(msg)
  21.         -- get the game object server
  22.         local gameObjectServer = getGameObjectServer();
  23.         -- get character who initiated this action
  24.         local character = getStateObjectFromID(msg.sender);
  25.         -- walk to the closest action point
  26.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"layDown1", "layDown2"});
  27.         -- get the walk state object
  28.         local wso = character.walkSO;
  29.         if (actionPoint) then
  30.             -- create state machine contexts
  31.             local wsoContext = StateMachineContext();
  32.             -- store the action point
  33.             wsoContext.storeData("actionPointName", actionPoint.getName());
  34.             if (wso.walkToActionPoint(actionPoint)) then
  35.                 wso.queueStateMachine("bedChar.layDown", this, wsoContext);
  36.             else
  37.                 print("no path found");
  38.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  39.             end
  40.         else
  41.             print("bed.lua no action point found of layDown1, layDown2");
  42.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  43.         end
  44.     end )
  45.             
  46. endStateMachine()
  47.